1834B - Maximum Strength - CodeForces Solution


greedy math

Please click on ads to support us..

C++ Code:

//=======================^========================================================^=======================\\
 
/*
* * * * * * * * *     * * * * * *       * * * * * *       * * * * * * * *   * * *       * * *
 * * * * * * * * *   * * * * * * * *   * * * * * * * *    * * * * * * * *   * * *       * * *
 * * *       * * *   * * *     * * *   * * *     * * *    * * * * * * * *   * * *       * * *
 * * *       * * *   * * *     * * *   * * *     * * *         * * *        * * *       * * *
 * * *       * * *   * * *     * * *   * * *     * * *         * * *        * * *       * * *
 * * * * * * * * *   * * * * * * * *   * * * * * * * *         * * *        * * * * * * * * *
 * * * * * * * * *   * * * * * * * *   * * * * * * *           * * *        * * * * * * * * *
 * * * * * * * * *   * * * * * * * *   * * * * *               * * *        * * * * * * * * *
 * * *               * * *     * * *   * * * * * *             * * *        * * *       * * *
 * * *               * * *     * * *   * * *  * * *            * * *        * * *       * * *
 * * *               * * *     * * *   * * *   * * *           * * *        * * *       * * *
 * * *               * * *     * * *   * * *    * * *          * * *        * * *       * * *
 * * *               * * *     * * *   * * *     * * *         * * *        * * *       * * *
 
*/
 
//=======================^========================================================^=======================\\
 
#include<iostream>
#include<math.h>
#include<stdlib.h>
// #include<bits/stdc++.h>
#include<string.h>
#include<ctype.h>
#include<set>
#include<vector>
#include <algorithm>
#include<map>
#define test ll t;cin>>t;while(t--)
#define ll long long int
#define lld long double
#define f first
#define s second
#define inarr ll n;cin>>n;ll arr[n+1];fi(0,n) cin>>arr[i]
#define setfor for(auto it: s1)
#define parthparekh ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fi(l,r) for(ll i = l; i < r; i++)
#define fj(l,r) for(ll j = l; j < r; j++)
#define fk(l,r) for(ll k = l; k < r; k++)
#define fir(r,l) for(ll i=r;i>=l;i--)
#define fjr(r,l) for(ll j=r;j>=l;j--)
const ll MOD=1e9+7;
const ll MOD2= 998244353;
const ll inf=1e18;
const ll N=1e6+100;
#define pb push_back
#define em emplace_back
#define yy cout<<"YES\n"
#define nn cout<<"NO\n"
using namespace std;
int main()
{
    parthparekh;
    ll t;
    cin>>t;
    while(t--){
        ll ans=0,ans1=0;
        string s1,s2;
        cin>>s1>>s2;
        if(s1==s2)
        cout<<0<<endl;
        else{
        if(s1.length()==s2.length()){
            fi(0,s1.length()){
                    if(s2[i]==s1[i])
                    ans1++;
                    else
                    break;
            }
            ans=((s1.length()-ans1-1)*9)+(s2[ans1]-s1[ans1]);
            cout<<ans<<endl;
        }
        else{
            cout<<(s2[0]-48)+(s2.length()-1)*9<<endl;
        }
        }
    }
}


Comments

Submit
0 Comments
More Questions

1672B - I love AAAB
1673A - Subtle Substring Subtraction
1345A - Puzzle Pieces
711A - Bus to Udayland
779B - Weird Rounding
1703D - Double Strings
1704C - Virus
63A - Sinking Ship
1704B - Luke is a Foodie
298B - Sail
239A - Two Bags of Potatoes
1704E - Count Seconds
682A - Alyona and Numbers
44A - Indian Summer
1133C - Balanced Team
1704A - Two 0-1 Sequences
1467A - Wizard of Orz
1714E - Add Modulo 10
1714A - Everyone Loves to Sleep
764A - Taymyr is calling you
1714B - Remove Prefix
1264F - Beautiful Fibonacci Problem
52A - 123-sequence
1543A - Exciting Bets
1714D - Color with Occurrences
215B - Olympic Medal
1445A - Array Rearrangment
1351A - A+B (Trial Problem)
935B - Fafa and the Gates
1291A - Even But Not Even